<template>
  <div class="avue-sidebar">
    <logo></logo>
    
    <el-scrollbar style="height:100%">
      <div v-if="validatenull(menu)"
           class="avue-sidebar--tip">{{$t('menuTip')}}</div>
      <el-menu unique-opened
               :default-active="nowTagValue"
               mode="vertical"
               :show-timeout="200"
               :collapse="keyCollapse">
        <sidebar-item :menu="menu"
                      :screen="screen"
                      first
                      :props="website.menu.props"
                      :collapse="keyCollapse"></sidebar-item>
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { reqCommonMsg } from '@/util/reqCommonMsg';
import { mapGetters } from 'vuex';
import {setStore, getStore} from '@/util/store'
import logo from '../logo';
import sidebarItem from './sidebarItem';
export default {
  name: 'sidebar',
  components: { sidebarItem, logo },
  data() {
    return {
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition:[],
        orderRule: {},
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {}
    };
  },
  created() {
    this.singleBody = {
      level: this.$getStore({name: this.userInfo.userId+'activeIndex'}) || 1,
      userId: this.userInfo.userId
    }
    this.reqParams =  {
      transCode: '0001',
      singleBody: this.singleBody,
      currentPage: 1, 
      pageSize: this.website.maxPageSize
    }
    //获取菜单
    this.commonData = {
      commonArea: reqCommonMsg(this.reqParams),
      level:  this.$getStore({name: this.userInfo.userId+'activeIndex'}) || 1,
      recordChanged: this.recordChanged || false
    }
    //this.$store.commit('DEL_TAG_NOT_IN_MENU1');
    this.$store.dispatch('GetMenu', this.commonData).then(data => {
      if (data.length === 0) return;
      this.$router.$avueRouter.formatRoutes(data, true);
    });
    //获取按钮
    let buttonCommonData = {
      commonArea: reqCommonMsg(this.reqParams),
      level: 1,
      recordChanged: this.recordChanged || false
    }
    this.$store.dispatch('GetButtons', buttonCommonData).then(data => {
      let permissionSign =  this.$toolUtil.encodeMd5(JSON.stringify(this.$getStore({name: this.userInfo.userId+'permission'})));
      let permission = this.$getStore({name: this.userInfo.userId+'permission'})
      let privatePermission = {
        data: permission,
        sign: permissionSign
      }
      sessionStorage.setItem(this.userInfo.userId+'privatePermission',JSON.stringify(privatePermission));
    });
  },
  computed: {
    ...mapGetters(['website','userInfo','recordChanged','permission', 'menu', 'tag', 'keyCollapse', 'screen']),
    nowTagValue: function() {
      return this.$router.$avueRouter.getValue(this.$route);
    }
  },
  mounted() {
   
  },
  methods: {}
};
</script>
<style lang="scss" scoped>
</style>

